//index.js
//获取应用实例
const app = getApp()
var token = wx.getStorageSync('token');
Page({
  data: {
    imgUrls: [
    ],
    smallBanner:[],
    a:"首页",
    autoplay: true,
    interval: 3000,
    interva2: 5000,
    duration: 1000,
    duration2: 1000,
    circular: true,
    coupondisplay: 'none',
    // classifications:[
    //   // "../activity/activity"
    //   { url: "../yuyue/yuyue", src: "../../images/yuyue.png", text: "预约", types:'navigate',huodong:'tz1' },
    //   { url: "../order/order", src: "../../images/diancan.png", text: "点餐", types: 'switchTab', huodong: 'tz2' },
    //   { url: "../facePay/facePay", src: "../../images/dangmianfu.png", text: "当面付", types: 'navigate', huodong: 'tz3' }, 
    //   { url: "../index/index", src: "../../images/huodong.png", text: "活动", types: 'switchTab', huodong: 'huodong' },
    //   { url: "../index/index", src: "../../images/miaosha.png", text: "秒杀", types: 'navigate', huodong: 'huodong'  },
    //   { url: "../index/index", src: "../../images/pintuan.png", text: "拼团", types: 'navigate', huodong: 'huodong' },
    //   { url: "../index/index", src: "../../images/choujiang.png", text: "抽奖", types: 'navigate', huodong: 'huodong'  },
    //   { url: "../newMan/newMan", src: "../../images/xinren.png", text: "新人专享", types: 'navigate', huodong: 'tz8' },
    // ],
    coupon:{
    },
    specials2:[
      { id: '1', pic: '/images/cm.png', title: "新品推荐", description:"超值抢购专场",img:"/images/cz.png" ,tip:"新品"},
      { id: '2', pic: '/images/bnm.png', title: '新品热卖', description: "品牌折扣 热卖来袭", img: "/images/dm.png" ,tip:"热卖"}
    ],
    recommends:[]
  },
  onLoad: function () {
    var that = this;

    // 轮播
    wx.request({
      url: app.globalData.directory + 'api/v2/banner/1', //仅为示例，并非真实的接口地址
      data: {
       
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': token
      },
      success: function (res) {
        if (res.data.status == 'ok') {
          console.log('11',res.data);
          that.setData({
            imgUrls:res.data.data.item
          })

        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });
    //中间小导航
    wx.request({
      url: app.globalData.directory + 'api/v2/banner/2',
      data:{},
      header:{
        'content-type': 'application/json', // 默认值
        'token': token
      },
      success: function(res) {
        console.log("中间小导航",res)
        if (res.data.status == "ok") {
          console.log('22',res.data.data.item);
          that.setData({
            smallBanner:res.data.data.item,
            coupondisplay:'block'
          })
        }
      }
    })   

    // 美食专题
    wx.request({
      url: app.globalData.directory + 'api/v2/special/getspecial', //仅为示例，并非真实的接口地址
      data: {
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': token
      },
      success: function (res) {
        if (res.data.status == 'ok') {
          console.log('美食专题', res.data.data);
          var specials2 = that.data.specials2
          var specials = res.data.data
          for(var i=0;i<specials2.length;i++){
            specials[i].img = specials2[i].img
          }
          that.setData({
            specials: res.data.data
          })
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });

    // 推荐菜品
    wx.request({
      url: app.globalData.directory + 'api/v2/getHomePageRecommend', //仅为示例，并非真实的接口地址
      data: {
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': token
      },
      success: function (res) {
        if (res.data.status == 'ok') {
          console.log('食品推荐', res.data.data);
          that.setData({
            recommends:res.data.data
          })
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });
  },
  huodong:function(){
    wx.showToast({
      title: '此活动暂未开启',
      icon: 'none',
      duration: 2000,
    })
  }
 
})  
